enum CharacterType {
  researcher,  // 现代研究人员
  mythological // 神话人物
}

class Character {
  final String id;
  final String name;
  final String description;
  final String imageUrl;
  final bool isUnlocked;
  final int requiredCoins;
  final CharacterType type;
  final String? lastMessage;
  final DateTime? lastMessageTime;
  final String? personality;
  final List<String>? topics;
  final int chatCount;

  const Character({
    required this.id,
    required this.name,
    required this.description,
    required this.imageUrl,
    required this.isUnlocked,
    required this.requiredCoins,
    required this.type,
    this.lastMessage,
    this.lastMessageTime,
    this.personality,
    this.topics,
    this.chatCount = 0,
  });

  factory Character.fromJson(Map<String, dynamic> json) {
    return Character(
      id: json['id'] as String,
      name: json['name'] as String,
      description: json['description'] as String,
      imageUrl: json['imageUrl'] as String,
      isUnlocked: json['isUnlocked'] as bool,
      requiredCoins: json['requiredCoins'] as int,
      type: CharacterType.values[json['type'] as int],
      lastMessage: json['lastMessage'] as String?,
      lastMessageTime: json['lastMessageTime'] != null ? DateTime.parse(json['lastMessageTime'] as String) : null,
      chatCount: json['chatCount'] as int? ?? 0,
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'name': name,
      'description': description,
      'imageUrl': imageUrl,
      'isUnlocked': isUnlocked,
      'requiredCoins': requiredCoins,
      'type': type.index,
      'lastMessage': lastMessage,
      'lastMessageTime': lastMessageTime?.toIso8601String(),
      'chatCount': chatCount,
    };
  }
} 